home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr22 / sendcod1.zip / SENDCODE.ASM next >
Assembly Source File  |  1993-05-03  |  4KB  |  121 lines

  1. ;
  2. ; What this program does:
  3. ; ----------------------
  4. ;
  5. ; SENDCODE.COM takes ASCII bytes (in hex) from its command line
  6. ; and sends the bytes to STDOUT. Note all the DOS output redirections
  7. ; can be used with this program, and the program is case-insensitive.
  8. ; The redirections allow sending an arbitrary sequence of bytes
  9. ; (max. about 40 ASCIIhex bytes) to be sent, for instance, to the
  10. ; printer port to set a desired mode.
  11. ;
  12. ; EXAMPLE (with ANSI.SYS installed): SENDCODE 1b 5B 32 4a
  13. ;        sends the sequence <ESC>[2J to stdout, which clears the screen
  14. ;        and leaves the cursor in the home position. Note 'b' == 'B'.
  15. ;
  16. ; Program History and Attributions:
  17. ; --------------------------------
  18. ;
  19. ;    This MASM version of SENDCODE was derived from a DEBUG script printed
  20. ;    in the User-to-User article of the September 27, 1988 issue of
  21. ;    PC Magazine. The original submission to the magazine was from Mike S.
  22. ;    O'Donnell of Worthington, Ohio. Mr. O'Donnell's program sent bytes
  23. ;    directly to the printer port. The author of the magazine article took
  24. ;    Mr. O'Donnell's suggestion to use STDOUT instead of PRN, and modified
  25. ;    the code, which then became the script printed in the article.
  26. ;
  27. ;    The DEBUG script author is Salvatore P. Ricciardi.
  28. ;    The entire contents of the Sept. 27, 1988 issue of PC Magazine is
  29. ;    Copyright (C) 1988 by Ziff-Davis Publishing Co., a division of
  30. ;      Ziff Communications Co.
  31. ;
  32. ;    This MASM version adds comments, jump labels, and a check for DOS
  33. ;    versions earlier than 2.0.
  34. ;
  35. ; Motivation for using this program:
  36. ; ---------------------------------
  37. ;
  38. ;    I use the installable ANSI device driver so that I can send escape
  39. ;    sequences to the console to set the foreground and background colors,
  40. ;    and use escape sequences in my DOS command line prompt. My previous
  41. ;    method was to create a number of different text files each containing
  42. ;    an escape sequence sent to the console using the TYPE command in a
  43. ;    batch file. Each text file was no more than about 10 bytes long, which
  44. ;    is really a terrible waste of disk space given that my cluster size
  45. ;    is 4,096 bytes! (For the uninitiated, a cluster is the smallest unit of
  46. ;    disk space allocated by DOS)
  47. ;
  48. ;    With this program, I can at least bury the sequences in my batch files,
  49. ;    which also are much shorter than a cluster. I can essentially reduce
  50. ;    the filesystem fragmentation slightly.
  51. ;
  52. ; The source code for the program:
  53. ; -------------------------------
  54. ;
  55. CMDLoffs    EQU    81h    ; offset into PSP where command line begins
  56. ;
  57. CSEG    SEGMENT
  58.     ASSUME CS:CSEG, DS:CSEG
  59. ;
  60.     ORG    100h    ; use .COM memory layout
  61. ;
  62. START:    mov    AH, 30h
  63.     int    21h    ; INT 21h service 30h: Get DOS Version Number
  64.     cmp    AL, 2    ; Major version returned in AL, Minor in AH
  65.     jb    OLDext    ; Exit if not at least Version 2.0
  66. ;
  67.     mov    BX, CMDLoffs    ; register int BX = CMDLoffs,
  68.     mov    CL, 4        ; CL = 4,
  69.     xor    DL, DL        ; DL = 0
  70. ;
  71. getch:    mov    AL, [BX]    ; DS:[BX] points to command line char in PSP
  72.     cmp    AL, 0Dh
  73.     je    fini        ; command line is terminated by a <CR> (0Dh)
  74. ;
  75.     cmp    AL, 30h
  76.     jb    nextch
  77.     cmp    AL, 39h
  78.     jbe    convt        ; char is in [0-9], convert hex nibble
  79. ;
  80.     and    AL, 0DFh    ; make [A-F, a-f] case-insensitive
  81. ;
  82.     cmp    AL, 41h
  83.     jb    nextch
  84.     cmp    AL, 46h
  85.     ja    nextch
  86. ;
  87.     sub    AL, 7        ; char is in [A-F], shift 'A' to 3Ah.
  88.                 ; 3Ah == '9' + 1 == 39h + 1
  89. ;
  90. convt:    sub    AL, 30h        ; convert ASCIIhex digit to nibble
  91.     rol    AL, CL        ; advance first digit to upper nibble when
  92.                 ; CL == 4, otherwise this is a NOP
  93. ;
  94.     add    DL, AL        ; accumulate nibble
  95.     cmp    CL, 0
  96.     jne    setCL        ; get lower nibble if CL == 4
  97.     mov    AH, 02h
  98.     int    21h    ;INT 21h service 02h: Output Character to STDOUT
  99.             ; character byte is in DL, output to device if
  100.             ; output has been redirected (Version 2.0+)
  101.     xor    DL, DL
  102. setCL:    xor    CL, 4        ; toggle CL between CL == 0 and CL == 4
  103. ;
  104. nextch:    inc    BX        ; move pointer to next command line char
  105.     jmp    getch
  106. ;
  107. fini:    mov    AX, 4C00h
  108.     int    21h    ; INT 21h service 4Ch: Process Terminate
  109.             ; AL contains return code which can be examined by
  110.             ; using the ERRORLEVEL variable in a batch file.
  111. ;
  112. OLDext:    int    20h    ; terminate DOS Version 1.x process. Does not allow
  113.             ; passing a return code to DOS. Don't trust possibly
  114.             ; redirected error message will be seen, so no error
  115.             ; message is printed.
  116. ;
  117. CSEG    ENDS
  118. ;
  119.     END    START
  120.  
  121.